home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / dos32xtn / bugfix / src / libdos32 / libc / dos32 / exceptn.s next >
Encoding:
Text File  |  1996-10-05  |  9.5 KB  |  415 lines

  1. /*
  2.  this file was changed or created for the DOS32 library for DJGPP on 5.10.1996
  3.  new created files are copyright 1996 by C.Lageman, see docs.doc for details
  4. */
  5. /*
  6.    This file contains the exception handlers and interrupts needed for
  7.    the dos32 library.
  8.  
  9.    problem: Unter the dos32 environment the IRQs 0-7 and expections 8-15
  10.             use the same interrupt handlers, so we must check in these
  11.             expections, if the called handler is really an expection or
  12.             just an IRQ. In the second case the int is chained down to the
  13.             old handler.
  14.             Of course, this can cause a noticeable (?) slowdown of the machine,
  15.             so installing these handlers or just only the expection 8 (which
  16.             blocks the timer IRQ) can be disabled by __crt0_startup_flags.
  17.    problem: should the exit proc called on an exception program abort
  18.             rather than directly exiting ?
  19. */
  20.         .file "exceptn.s"
  21.         .text
  22.  
  23.  
  24. /*
  25.    this handler should be aligned 16, because it's called very often
  26. */
  27. .align 16
  28. handler8:
  29.         pushl   %eax
  30.         movl    $___dos32_oldints+0xf*8,%eax
  31.         call    testirq
  32.         pushl   %eax
  33.         movl    $msgexp8,%eax
  34.         jmp     saveregs
  35. handler9:
  36.         pushl   %eax
  37.         movl    $___dos32_oldints+9*8,%eax
  38.         call    testirq
  39.         sub     $4,%esp
  40.         pushl   %eax
  41.         movl    $msgexp9,%eax
  42.         jmp     saveregs
  43. handlera:
  44.         pushl   %eax
  45.         movl    $___dos32_oldints+0xa*8,%eax
  46.         call    testirq
  47.         pushl   %eax
  48.         movl    $msgexpa,%eax
  49.         jmp     saveregs
  50. handlerb:
  51.         pushl   %eax
  52.         movl    $___dos32_oldints+0xb*8,%eax
  53.         call    testirq
  54.         pushl   %eax
  55.         movl    $msgexpb,%eax
  56.         jmp     saveregs
  57. handlerc:
  58.         pushl   %eax
  59.         movl    $___dos32_oldints+0xc*8,%eax
  60.         call    testirq
  61.         pushl   %eax
  62.         movl    $msgexpc,%eax
  63.         jmp     saveregs
  64. handlerd:
  65.         pushl   %eax
  66.         movl    $___dos32_oldints+0xd*8,%eax
  67.         call    testirq
  68.         pushl   %eax
  69.         movl    $msgexpd,%eax
  70.         jmp     saveregs
  71. handlere:
  72.         pushl   %eax
  73.         movl    $___dos32_oldints+0xe*8,%eax
  74.         call    testirq
  75.         pushl   %eax
  76.         movl    $msgexpe,%eax
  77.         jmp     saveregs
  78. handler0:
  79.         pushl   %eax
  80.         movl    $msgexp0,%eax
  81.         jmp     saveregs
  82. handler2:
  83.         pushl   %eax
  84.         movl    $msgexp2,%eax
  85.         jmp     saveregs
  86. handler4:
  87.         pushl   %eax
  88.         movl    $msgexp4,%eax
  89.         jmp     saveregs
  90. handler5:
  91.         pushl   %eax
  92.         movl    $msgexp5,%eax
  93.         jmp     saveregs
  94. handler6:
  95.         pushl   %eax
  96.         movl    $msgexp6,%eax
  97.         jmp     saveregs
  98. handler7:
  99.         pushl   %eax
  100.         movl    $msgexp7,%eax
  101.  
  102. saveregs:
  103.         pushl   %ds
  104.         cs
  105.         movw    ___dos32_ds,%ds
  106.         movl    %eax,expmsg
  107. /*
  108.     get old ds & save
  109. */
  110.         popl    %eax
  111.         movl    %eax,regstore+16
  112. /*
  113.     restore eax
  114. */
  115.         popl    %eax
  116.         movl    %esp,esptemp
  117.         movw    %ss,sstemp
  118.         pushl   %ds
  119.         popl    %ss
  120.         movl    $regstoreend,%esp
  121.         pusha
  122.         pushl   %gs
  123.         pushl   %fs
  124.         pushl   %es
  125.         movl    esptemp,%esp
  126.         movw    sstemp,%ss
  127.         popl    regstore+4
  128.         popl    regstore
  129.         movl    %esp,regstore+12
  130.         popl    regstoreend
  131.         movl    %ss,regstore+8
  132.         
  133.  
  134.         movl    $expmask,%ecx
  135.         call    dumpmsg
  136.         movl    expmsg,%ecx
  137.         call    dumpmsg
  138.  
  139.         cld
  140.         movl    $regaddr,%esi
  141.         movl    $regstore,%edx
  142.         xorl    %ecx,%ecx
  143. regs2hex:
  144.         movl    (%esi),%edi
  145.         movl    (%edx),%ebx
  146.         orl     %edi,%edi
  147.         jz      hexdone
  148.         addl    $4,%edx
  149.         addl    $4,%esi
  150.         movb    $8,%cl
  151. inner:
  152.         xorl    %eax,%eax
  153.         shldl   $4,%ebx,%eax
  154.         movb    hexstring(%eax),%al
  155.         ds
  156.         stosb
  157.         shl     $4,%ebx
  158.         decl    %ecx
  159.         jnz     inner
  160.         
  161.         jmp     regs2hex
  162. hexdone:
  163.         movl    $regmask,%ecx
  164.         call    dumpmsg
  165. leaveme:
  166.         movw    $0x4c01,%ax
  167.         int     $0x21
  168.  
  169. .align  16
  170. testirq:
  171. /*
  172.  eax - address of pointer to old int
  173.   stack:
  174.  esp+16  [   app eflags    ]
  175.  esp+12  [  XXXX  | app cs ]
  176.  esp+8   [     app eip     ]
  177.  esp+4   [       eax       ]
  178.  esp     [    caller eip   ]
  179. */
  180.         pushl   %eax
  181.         inb     $0x21,%al
  182.         outb    %al,$0x21
  183.         movb    $0x40,%al
  184.         outb    %al,$0x20
  185.         movb    $0x0B,%al
  186.         outb    %al,$0x20
  187.         inb     $0x20,%al
  188.         orb     %al,%al
  189.         popl    %eax
  190.         jz      1f
  191.  
  192.         cs
  193.         pushl   4(%eax)
  194.         cs
  195.         pushl   (%eax)
  196. /*
  197.    stack:
  198.  esp+26  [    app eflags   ]
  199.  esp+24  [  XXXX  | app cs ]
  200.  esp+16  [     app eip     ]  <--- at this point esp will be after lret
  201.  esp+12  [       eax       ]  removed by lret $8
  202.  esp+8   [    caller eip   ]  removed by lret $8
  203.  esp+4   [  XXXX  | int cs ]
  204.  esp     [     int  eip    ]
  205. */
  206.         movl    12(%esp),%eax
  207.         lret    $8
  208. 1:
  209.         movl    4(%esp),%eax
  210.         ret     $8
  211.  
  212. dumpmsg:
  213.       movb     $6,%ah
  214. 1:    movb     (%ecx),%dl
  215.       orb      %dl,%dl
  216.       jz       2f
  217.       incl     %ecx
  218.       int      $0x21
  219.       jmp      1b
  220. 2:    ret
  221.  
  222.  
  223. /*
  224.       bios ctrl-break
  225. */
  226. int1b:
  227.       pushl    %ds
  228.       cs
  229.       movw     ___dos32_ds,%ds
  230.       testb    $1,___dos32_cbreak_mode
  231.       jz       cbreak_exit
  232.       testb    $2,___dos32_cbreak_mode
  233.       jz       1f
  234.       movb     $1,___dos32_cbreak_counter
  235. 1:
  236.       popl     %ds
  237.       iret
  238.  
  239. cbreak_exit:
  240.       movl     $cbreakmsg,%ecx
  241.       call     dumpmsg
  242.       jmp      leaveme
  243.  
  244. /*
  245.       dos ctrl-c / ctrl - break
  246.       this is faked by just using the identical int1b handler
  247. int23:
  248.       jmp      int1b
  249. */
  250.  
  251. /*
  252.       critical error handler with 3 retries (remove retrys ?)
  253. */
  254. int24:
  255.         testb   $0x80,%ah
  256.         jnz     fail_int24
  257.         pushl   %ds
  258.         pushl   %esi
  259.         cs
  260.         movw    ___dos32_ds,%ds
  261.         cmpb    errordrive,%al
  262.         movl    $error_retries,%esi
  263.         je      1f
  264.         movb    %al,errordrive
  265.         movb    $0,(%esi)
  266. 1:      incb    (%esi)
  267.         cmpb    $3,(%esi)
  268.         popl    %esi
  269.         popl    %ds
  270.         ja      fail_int24
  271.         movb    $1,%al
  272.         clc
  273.         lret
  274. fail_int24:
  275.         movb    $3,%al
  276.         clc
  277.         lret
  278.  
  279.         .data
  280.         .lcomm  esptemp,4
  281.         .lcomm  sstemp,2
  282. errordrive:
  283.         .byte   0xff
  284.         .lcomm  error_retries,1
  285.  
  286. hexstring:
  287.         .ascii  "0123456789ABCDEF"
  288.  
  289.         .lcomm   regstore,68
  290. .set regstoreend, regstore + 64
  291.  
  292.         .lcomm  expmsg,4
  293.  
  294. regaddr:
  295.         .long   reg1,reg2,reg3,reg4,reg5,reg6,reg7,reg8,reg14
  296.         .long   reg13,reg15,reg10,reg10,reg12,reg11,reg9,reg16,0
  297.  
  298. msgexp0:
  299.         .asciz  "0 - division by zero"
  300. msgexp2:
  301.         .asciz  "2 - non maskable interrupt"
  302. msgexp4:
  303.         .asciz  "4 - overflow"
  304. msgexp5:
  305.         .asciz  "5 - bound range exceeded$"
  306. msgexp6:
  307.         .asciz  "6 - invalib opcode"
  308. msgexp7:
  309.         .asciz  "7 - coprocessor not aviable"
  310. msgexp8:
  311.         .asciz  "8 - double fault"
  312. msgexp9:
  313.         .asciz  "9 - coprocessor segment overrun"
  314. msgexpa:
  315.         .asciz  "10 - invalid TSS"
  316. msgexpb:
  317.         .asciz  "11 - segment not present"
  318. msgexpc:
  319.         .asciz  "12 - stack exception"
  320. msgexpd:
  321.         .asciz  "13 - general protection fault"
  322. msgexpe:
  323.         .asciz  "14 - page fault"
  324.  
  325.  
  326. expmask:
  327.         .asciz  "exception "
  328. regmask:
  329.         .byte   13,10
  330.         .ascii  "CS:EIP - "
  331. reg1:
  332.         .ascii  "MISSING!:"
  333. reg2:
  334.         .ascii  "MISSING!     SS:ESP - "
  335. reg3:
  336.         .ascii  "MISSING!:"
  337. reg4:
  338.         .ascii  "MISSING!"
  339.         .byte   13,10
  340.         .ascii  "DS:  "
  341. reg5:
  342.         .ascii  "MISSING!   ES:  "
  343. reg6:
  344.         .ascii  "MISSING!   FS:  "
  345. reg7:
  346.         .ascii  "MISSING!   GS:  "
  347. reg8:
  348.         .ascii  "MISSING!"
  349.         .byte   13,10
  350.         .ascii  "EAX: "
  351. reg9:
  352.         .ascii  "MISSING!   EBX: "
  353. reg10:
  354.         .ascii  "MISSING!   ECX: "
  355. reg11:
  356.         .ascii  "MISSING!   EDX: "
  357. reg12:
  358.         .ascii  "MISSING!"
  359.         .byte   13,10
  360.         .ascii  "ESI: "
  361. reg13:
  362.         .ascii  "MISSING!   EDI: "
  363. reg14:
  364.         .ascii  "MISSING!   EBP: "
  365. reg15:
  366.         .ascii  "MISSING! FLAGS: "
  367. reg16:
  368.         .ascii  "MISSING!"
  369.         .byte   13,10
  370.         .ascii  "Program abort !"
  371.         .byte   13,10,0
  372.  
  373. cbreakmsg:
  374.         .ascii  "Exit due to <CTRL-BREAK>"
  375.         .byte   13,10,0
  376.  
  377.         .global ___dos32_new_ints
  378. ___dos32_new_ints:
  379.         .byte   0x1b
  380.         .long   int1b
  381.         .byte   0x23
  382.         .long   int1b
  383.         .byte   0x24
  384.         .long   int24
  385.         .byte   0x0
  386.         .long   handler0
  387.         .byte   0x2
  388.         .long   handler2
  389.         .byte   0x4
  390.         .long   handler4
  391.         .byte   0x5
  392.         .long   handler5
  393.         .byte   0x6
  394.         .long   handler6
  395.         .byte   0x7
  396.         .long   handler7
  397.         .byte   0x9
  398.         .long   handler9
  399.         .byte   0xa
  400.         .long   handlera
  401.         .byte   0xb
  402.         .long   handlerb
  403.         .byte   0xc
  404.         .long   handlerc
  405.         .byte   0xd
  406.         .long   handlerd
  407.         .byte   0xe
  408.         .long   handlere
  409.         .byte   0x8
  410.         .long   handler8
  411.         .byte   0xff
  412. /*
  413. ********************    end of exceptn.s **********************************
  414. */
  415.